package com.ruoyi.model.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.model.domain.ModelAlgorithm;
import com.ruoyi.model.domain.ModelScheme;
import com.ruoyi.model.domain.vo.ModelAlgorithmVo;
import com.ruoyi.model.service.IModelAlgorithmService;
import com.ruoyi.model.service.IModelSchemeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 模型算法管理Controller
 *
 * @author rww
 * @date 2024-11-25
 */
@RestController
@RequestMapping("/model/scheme")
public class ModelSchemeController extends BaseController
{
    @Autowired
    private IModelSchemeService modelSchemeService;

    /**
     * 查询策略管理列表
     */
    @PreAuthorize("@ss.hasPermi('model:scheme:list')")
    @GetMapping("/list")
    public TableDataInfo list(ModelScheme modelScheme)
    {
        startPage();
        List<ModelScheme> list = modelSchemeService.selectModelSchemeList(modelScheme);
        return getDataTable(list);
    }

    /**
     * 查询策略管理-不带分页
     * **/

    @GetMapping("/noPageList")
    public AjaxResult noPageList(ModelScheme modelScheme)
    {
        List<ModelScheme> list = modelSchemeService.selectModelSchemeList(modelScheme);
        return AjaxResult.success(list);
    }

    /**
     * 导出策略管理列表
     */
    @PreAuthorize("@ss.hasPermi('model:scheme:export')")
    @Log(title = "策略管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ModelScheme modelScheme)
    {
        List<ModelScheme> list = modelSchemeService.selectModelSchemeList(modelScheme);
        ExcelUtil<ModelScheme> util = new ExcelUtil<ModelScheme>(ModelScheme.class);
        util.exportExcel(response, list, "模型管理数据");
    }

    /**
     * 获取策略管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('model:scheme:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(modelSchemeService.selectModelSchemeById(id));
    }

    /**
     * 新增策略管理
     */
    @PreAuthorize("@ss.hasPermi('model:scheme:add')")
    @Log(title = "策略管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ModelScheme modelScheme)
    {
        return toAjax(modelSchemeService.insertModelScheme(modelScheme));
    }

    @PreAuthorize("@ss.hasPermi('model:scheme:set-param')")
    @Log(title = "策略管理", businessType = BusinessType.INSERT)
    @PostMapping("set-param")
    public AjaxResult setParam(@RequestBody ModelScheme modelScheme)
    {
        return  null;
//        return toAjax(modelAlgorithmService.setModelAlgorithm(modelAlgorithm));
    }

    /**
     * 修改模型管理
     */
    @PreAuthorize("@ss.hasPermi('model:scheme:edit')")
    @Log(title = "策略管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody ModelScheme modelScheme)
    {
        return toAjax(modelSchemeService.updateModelScheme(modelScheme));
    }

    /**
     * 删除模型管理
     */
    @PreAuthorize("@ss.hasPermi('model:scheme:remove')")
    @Log(title = "策略管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(modelSchemeService.deleteModelSchemeByIds(ids));
    }
}
